﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using NServiceBus;

namespace Authentication
{
    public class AuthenticationHandler:IHandleMessages<IMessage>
    {
        public IBus Bus { get; set; }

        public void Handle(IMessage message)
        {
            //get the content of the message for every sent
            var token = Bus.GetMessageHeader(message, "access_token");
            if (!token.Equals("authentic_user"))
            {
                Console.WriteLine("User is not Authenticated");
                Bus.DoNotContinueDispatchingCurrentMessageToHandlers();
            }
            Console.WriteLine("User is Authenticated");
        }
    }
}
